package translationModel;

import java.util.BitSet;

public class State implements Comparable<State>
{
	public String preLastWord;
	public String lastWord;
	public BitSet cover;
	public int fEndPoint;
	public int eEndPoint;
	public double score;
	public TranslatedPhrase phrase;
	public State prevState;
	
	public State() 
	{
	}
	
	public int hashCode() {
		if (preLastWord != null)
			return preLastWord.hashCode() ^ lastWord.hashCode() ^ cover.hashCode() ^ fEndPoint;
		return lastWord.hashCode() ^ cover.hashCode() ^ fEndPoint;
	}
	
	public boolean equals(Object obj)
	{
		if (!(obj instanceof State))
			return false;
		State other = (State)obj;
		return ((this.preLastWord.intern() == other.preLastWord.intern()) &&
				(this.lastWord.intern() == other.lastWord.intern()) && 
				(this.cover.equals(other.cover)) && (this.fEndPoint == other.fEndPoint));
	}
	
	public int compareTo(State other)
	{
		if (this.score < other.score)
			return 1;
		else if (this.score > other.score)
			return -1;
		return 0;
	}
}
